package com.example.customview.silder

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import com.example.customview.silder.RecycleAdapter

class SingleRecycleAdapter(
    @LayoutRes private val
    itemLayout: Int,
    brId: Int,
    brIndex: Int = 0,
    mItemClickListener: ((view: View, item: Any) -> Unit)? = null,
    mItemLongClickListener: ((view: View, item: Any) -> Boolean)? = null,
    viewHolder: ((viewBinding: ViewDataBinding, item:Any) -> Unit)? = null
) : RecycleAdapter(
    brId,
    brIndex,
    mItemClickListener,
    mItemLongClickListener, viewHolder
) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val binding =
            DataBindingUtil.inflate<ViewDataBinding>(
                LayoutInflater.from(parent.context),
                itemLayout,
                parent,
                false
            )
        (parent as RecyclerView).recycledViewPool.setMaxRecycledViews(viewType, 20)
        return ViewHolder(
            binding.root
        )
    }

    override fun getItemViewType(position: Int): Int = 0

    override fun getItemCount(): Int = data.size
}
